package com.jic.market.mapper.skill;

import com.jic.market.entity.skill.ActivityStoreConfig;

import com.jic.market.request.CouponDetailRequest;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 活动店铺基础配置表
 *
 * @author : seven
 * @version : v1.0.0
 * @email : 774329481@qq.com
 * @since : 2020-03-12 05:30:04
 */
@Repository
public interface ActivityStoreConfigMapper {

    long insert(ActivityStoreConfig activityStoreConfig);

    long delete(@Param("promotionId") String promotionId);

    long update(ActivityStoreConfig activityStoreConfig);

    ActivityStoreConfig queryByPrimaryKey(Long id);

    List<ActivityStoreConfig> query(ActivityStoreConfig activityStoreConfig);

    List<ActivityStoreConfig> queryPage(@Param("startIndex") int startIndex, @Param("limit") int limit, @Param("activityStoreConfig") ActivityStoreConfig activityStoreConfig);

    long queryPageCount(ActivityStoreConfig activityStoreConfig);

//    @Select("select * from  market_activity_store_config where promotion_id=#{promotionId} and delete_flag='0'")

    /**
     *
     * @param promotionId
     * @param start
     * @param limit
     * @return
     */
    List<ActivityStoreConfig> queryStoreByPromotionId(@Param("promotionId") String promotionId , @Param("start") Integer start , @Param("limit") Integer limit,@Param("storeIds") List<Long> storeIds,@Param("couponVo") CouponDetailRequest promotionIdRequest);


    @Select("select store_id from market_activity_store_config where promotion_id=#{promotionId} and delete_flag='0'")
    List<String> queryStoreIdByPromotionId(@Param("promotionId") String promotionId);

    @Update("update market_activity_store_config set delete_flag='1' where promotion_id=#{promotionId} and " +
            " merchant_id=#{merchantId}")
    long deleteStoreByPromotionIdAndMerchantId(@Param("promotionId") String promotionId,
                                               @Param("merchantId") String merchantId);

    @Update("update market_activity_store_config set delete_flag='1' where promotion_id=#{promotionId} and " +
            " store_id=#{storeId}")
    long deleteStoreByPromotionIdAndStoreId(@Param("promotionId") String promotionId,
                                            @Param("storeId") String storeId);

    Long queryByPromotionIdTotal(@Param("promotionId") String promotionId,@Param("storeIds") List<Long> storeIds,@Param("couponVo") CouponDetailRequest promotionIdRequest);

    @Select("select store_id from promotion_merchant where delete_flag = '0' and promotion_id = #{promotionId} and merchant_type = '2' ")
    List<Long> getStoreIdsByPromotionId(@Param("promotionId") String promotionId);

    @Select("select store_id from market_activity_store_config where delete_flag = '0' and promotion_id = #{promotionId} ")
    List<Long> getCouponStoreIdsByPromotionId(@Param("promotionId") String promotionId);

    int insertBatch(@Param("items") List<ActivityStoreConfig> storeConfigList);
}
